home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / ip / trace / tcpdump-2.2.1 / mkdep < prev    next >
Encoding:
Text File  |  1992-05-26  |  2.1 KB  |  103 lines

  1. #!/bin/sh -
  2. #
  3. # Copyright (c) 1987 Regents of the University of California.
  4. # All rights reserved.
  5. #
  6. # Redistribution and use in source and binary forms are permitted
  7. # provided that this notice is preserved and that due credit is given
  8. # to the University of California at Berkeley. The name of the University
  9. # may not be used to endorse or promote products derived from this
  10. # software without specific prior written permission. This software
  11. # is provided ``as is'' without express or implied warranty.
  12. #
  13. #    @(#)mkdep.sh    5.11 (Berkeley) 5/5/88
  14. #
  15.  
  16. PATH=/bin:/usr/bin:/usr/ucb
  17. export PATH
  18.  
  19. MAKE=Makefile            # default makefile name is "Makefile"
  20.  
  21. while :
  22.     do case "$1" in
  23.         # -f allows you to select a makefile name
  24.         -f)
  25.             MAKE=$2
  26.             shift; shift ;;
  27.  
  28.         # the -p flag produces "program: program.c" style dependencies
  29.         # so .o's don't get produced
  30.         -p)
  31.             SED='s;\.o;;'
  32.             shift ;;
  33.         *)
  34.             break ;;
  35.     esac
  36. done
  37.  
  38. if [ $# = 0 ] ; then
  39.     echo 'usage: mkdep [-p] [-f makefile] [flags] file ...'
  40.     exit 1
  41. fi
  42.  
  43. if [ ! -w $MAKE ]; then
  44.     echo "mkdep: no writeable file \"$MAKE\""
  45.     exit 1
  46. fi
  47.  
  48. TMP=/tmp/mkdep$$
  49.  
  50. trap 'rm -f $TMP ; exit 1' 1 2 3 13 15
  51.  
  52. cp $MAKE ${MAKE}.bak
  53.  
  54. sed -e '/DO NOT DELETE THIS LINE/,$d' < $MAKE > $TMP
  55.  
  56. cat << _EOF_ >> $TMP
  57. # DO NOT DELETE THIS LINE -- mkdep uses it.
  58. # DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.
  59.  
  60. _EOF_
  61.  
  62. # If your compiler doesn't have -M, add it.  If you can't, the next two
  63. # lines will try and replace the "cc -M".  The real problem is that this
  64. # hack can't deal with anything that requires a search path, and doesn't
  65. # even try for anything using bracket (<>) syntax.
  66. #
  67. # egrep '^#include[     ]*".*"' /dev/null $* |
  68. # sed -e 's/:[^"]*"\([^"]*\)".*/: \1/' -e 's/\.c/.o/' |
  69.  
  70. cc -M $* |
  71. sed "
  72.     s; \./; ;g
  73.     $SED" |
  74. awk '{
  75.     if ($1 != prev) {
  76.         if (rec != "")
  77.             print rec;
  78.         rec = $0;
  79.         prev = $1;
  80.     }
  81.     else {
  82.         if (length(rec $2) > 78) {
  83.             print rec;
  84.             rec = $0;
  85.         }
  86.         else
  87.             rec = rec " " $2
  88.     }
  89. }
  90. END {
  91.     print rec
  92. }' >> $TMP
  93.  
  94. cat << _EOF_ >> $TMP
  95.  
  96. # IF YOU PUT ANYTHING HERE IT WILL GO AWAY
  97. _EOF_
  98.  
  99. # copy to preserve permissions
  100. cp $TMP $MAKE
  101. rm -f ${MAKE}.bak $TMP
  102. exit 0
  103.